<template>
  <div>
    <!-- 搜索栏 -->
    <el-card id="serach">
      <el-row>
        <el-col :span="20">
          <el-input
            v-model="searchModel.username"
            placeholder="用户名"
            clearable
          ></el-input>
          <el-button
            type="success"
            plain
            icon="el-icon-search"
            @click="getUserList"
            >搜索</el-button
          >
        </el-col>
      </el-row>
    </el-card>

    <!-- 结果列表 -->
    <el-card>
      <el-table :data="userList" border style="width: 100%">
        <el-table-column label="#" width="30">
          <template slot-scope="scope">
            {{
              (searchModel.pageNo - 1) * searchModel.pageSize + 1 + scope.$index
            }}
          </template>
        </el-table-column>
        <el-table-column prop="id" label="用户id" width="180">
        </el-table-column>
        <el-table-column prop="username" label="用户名" width="180">
        </el-table-column>
        <el-table-column prop="phone" label="电话" width="180">
        </el-table-column>
        <el-table-column prop="avatar" label="头像" width="180">
          <div class="demo-image__preview">
          <template  slot-scope="scope">
            <img
              style="width: 80px; height: 80px"
              :src="'data:image/png;base64,' + scope.row.avatar"
            />
          </template>
          </div>
        </el-table-column>
        <el-table-column prop="usertime" label="注册时间"> </el-table-column>
        <el-table-column label="操作" width="180">
          <template slot-scope="scope">
            <el-button
              @click="deleteUser(scope.row)"
              type="danger"
              icon="el-icon-delete"
              size="mini"
              >删除用户</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </el-card>

    <!-- 分页 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="searchModel.pageNo"
      :page-sizes="[2, 5, 10, 20]"
      :page-size="searchModel.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
  </div>
</template>
  
  <script>
import eApi from "@/api/androiduser";
export default {
  data() {
    return {
      searchModel: {
        pageNo: 1,
        pageSize: 10,
      },
      total: 0,
      userList: [],
      userForm: {},
    };
  },
  created() {
    this.getUserList();
  },
  methods: {
    getUserList() {
      eApi.getAndroidUser(this.searchModel).then((Response) => {
        this.userList = Response.data.rows;
        this.total = Response.data.total;
      });
    },
    handleSizeChange(pageSize) {
      this.searchModel.pageSize = pageSize;
      this.getUserList();
    },
    handleCurrentChange(pageNo) {
      this.searchModel.pageNo = pageNo;
      this.getUserList();
    },
    clearFrom() {
      this.userform = {};
      this.$refs.userformref.clearValidate();
    },
    deleteUser(user) {
      this.$confirm(`您确认删除用户 ${user.username} ?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          eApi.deltUserById(user.id).then((response) => {
            this.$message({
              type: "success",
              message: response.message,
            });
            this.getUserList();
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },
};
</script>
  
  <style>
#serach .el-input {
  width: 200px;
  margin-right: 10px;
}
.el-dialog .el-input {
  width: 85%;
}
</style>